/*
 * This file is part of NativeAccessHooks.
 *
 * Copyleft 2014 Mark Jeronimus. All Rights Reversed.
 * https://code.google.com/p/nativeaccesshooks/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NativeAccessHooks. If not, see <http://www.gnu.org/licenses/>.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.digitalmodular.nah;

import java.util.EventObject;

/**
 * Superclass for all native events, containing the things all native events should have in common. In this case, two time stamps of
 * different resolution.
 * 
 * The time value can be used to know at which date and time of the day an event occurred.
 * 
 * The nanoTime value can be used to calculate the time difference between events more accurately than with the time value.
 * 
 * Subclasses can override {@link #toString()} and include <code>super.toString()</code> in the result.
 * 
 * All events are to be processed through one method, {@link HookManager#dispatchEvent(NativeInputEvent)}.
 * 
 * @author Mark Jeronimus
 * @since 1.0
 */
// date 2014-08-23
public abstract class NativeInputEvent extends EventObject {
	/** The time the event occurred (in Java {@link System#currentTimeMillis()} units). */
	private long	time;
	/** The time the event occurred (in Java {@link System#nanoTime()} units). */
	private long	nanoTime;

	/**
	 * Instantiates a new native input event.
	 * 
	 * @param source The source of the event.
	 * @param time The time the event occurred (from Java {@link System#nanoTime()}).
	 * @param nanoTime The nanoTime value of the virtual machine at the time the event occurred.
	 */
	public NativeInputEvent(NativeHook source, long time, long nanoTime) {
		super(source);

		this.time = time;
		this.nanoTime = nanoTime;
	}

	/**
	 * Returns time the event occurred (in Java {@link System#nanoTime()} units).
	 * 
	 * @return the timestamp in milliseconds
	 */
	public long getTime() {
		return time;
	}

	/**
	 * Returns time the event occurred (from Java {@link System#currentTimeMillis()}).
	 * 
	 * @return the timestamp in milliseconds
	 */
	public long getNanoTime() {
		return nanoTime;
	}

	@Override
	public String toString() {
		StringBuilder message = new StringBuilder();
		message.append("nanoTime=").append(nanoTime);
		return message.toString();
	}
}
